var t = getApp(), e = void 0;

Page({
    data: {
        chooseFlag: -1,
        seasonInput: ""
    },
    chooseReason: function(t) {
        var e = t.currentTarget.dataset.index;
        this.setData({
            chooseFlag: e
        });
    },
    inputSeason: function(t) {
        this.setData({
            seasonInput: t.detail.value
        });
    },
    onLoad: function(t) {
        (e = this).setData({
            order_id: t.order_id,
            order_no: t.order_no,
            type: t.type
        }), wx.setNavigationBarTitle({
            title: (1 == t.type ? "用户" : "跑男") + "取消订单"
        }), e.getOrder();
    },
    getSet: function() {
        wx.showLoading({
            title: "加载中"
        }), t.com.post("config/get", {
            config_key: "cancel_order"
        }, function(t) {
            wx.hideLoading(), 0 === t.errno && e.setData({
                config: t.data.config_content ? JSON.parse(t.data.config_content) : {}
            });
        });
    },
    getOrder: function() {
        t.com.post("wx/order/find", {
            order_no: this.data.order_no
        }, function(t) {
            0 === t.errno && (e.setData({
                order: t.data
            }), e.getOrderTimes());
        });
    },
    getOrderTimes: function() {
        t.com.post("wx/order/findtime", {
            order_id: this.data.order_id
        }, function(t) {
            0 === t.errno && (e.setData({
                ordertime: t.data
            }), e.getSet());
        });
    },
    refundIt: function() {
        wx.showModal({
            title: "提示",
            content: "您确定要取消吗？",
            success: function(o) {
                if (o.confirm) if (-1 == e.data.chooseFlag) wx.showToast({
                    title: "请选择一个理由",
                    icon: "none"
                }); else if (-2 == e.data.chooseFlag && "" == e.data.seasonInput) wx.showToast({
                    title: "请输入您的理由",
                    icon: "none"
                }); else {
                    wx.showLoading({
                        title: "加载中",
                        mask: !0
                    });
                    var a = 1 == e.data.type ? "user" : "runman", n = "";
                    n = -2 == e.data.chooseFlag ? e.data.seasonInput : 1 == e.data.type ? e.data.config.userReasons[e.data.chooseFlag] : e.data.config.runmanReasons[e.data.chooseFlag], 
                    t.com.post("wx/orderCancel/" + a, {
                        order_id: e.data.order_id,
                        seasonInput: n
                    }, function(t) {
                        wx.hideLoading(), 0 === t.errno && (wx.showToast({
                            title: "取消成功",
                            duration: 1e3,
                            mask: !0
                        }), setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3));
                    });
                }
            }
        });
    }
});